import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/cabinet/api/cabinetApi.dart';
import 'package:honeypotflutter/modules/cabinet/pages/cabinet_list_info/view.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_refresh.dart';
import '../../model/cabinet_list_model.dart';
import '../../views/cabinet_list_item.dart';
import 'logic.dart';

class CabinetListPage extends StatefulWidget {
  const CabinetListPage({Key? key}) : super(key: key);

  @override
  State<CabinetListPage> createState() => _CabinetListPageState();
}

class _CabinetListPageState extends State<CabinetListPage> {
  final CabinetListLogic logic = Get.put(CabinetListLogic());
  int page = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(
        navigationTitle: "柜机管理",
      ),
      body: HLRefresh<CabinetListModel>(onRefresh: () async {
        page = 1;
        return CabinetApi.cabinetList(page);
      }, onLoading: () async {
        page += 1;
        return CabinetApi.cabinetList(page);
      }, snap: (CabinetListModel model, int index) {
        return CabinetListItem(
            itemModel: model,
            itemAction: () {
              Get.to(CabinetListInfoPage(), arguments: model);
            });
      }),
    );
  }

  @override
  void dispose() {
    Get.delete<CabinetListLogic>();
    super.dispose();
  }
}
